﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kaixin.Components.InterFace;
using System.Threading;
using Kaixin.Components.Tycoon.BLL;

namespace Kaixin.Components.Tycoon
{
    /// <summary>
    /// 大亨具体组件类
    /// 创建：2009-12-9 14:54:21
    /// 版本：1.0
    /// 作者：吴鸣震
    /// </summary>
    class TycoonComponent : ComponentsBase
    {
        private TycoonRobot _root = new TycoonRobot();
        private Thread _backgroudThread;
        private IUIFactory _uif = new UIFactory();

        public TycoonComponent()
        {
            _backgroudThread = new Thread(ThreadWork);
            _backgroudThread.Name = "物品价格记录及委托交易线程";
            _backgroudThread.Start();
        }

        private void ThreadWork()
        {
            //价格浮动时进行委托交易观察
            _root.PriceChangeEvent += new TycoonRobot.PriceChange(Commission.Action);

            while (true)
            {
                try
                {
                    Thread.Sleep(1000 * 30);//半分钟刷一次
                    _root.GetGoods();
                }
                catch (Exception ex)
                {

                    Log.WriteLog(ex.Message, Name);
                }
            }
        }



        public override List<string> GetMenus()
        {
            List<string> menus = new List<string>();
            menus.Add("物品跌幅榜");
            menus.Add("委托单操作");
            return menus;
        }

        public override string Name
        {
            get { return "超级大亨"; }
        }

        public override IUIFactory UIFactory
        {

            get { return _uif; }
        }

        public override Thread BackgroundThread
        {
            get { return _backgroudThread; }
        }
    }
}
